package com.dony.web.controller.shop;

import com.dony.common.core.controller.BaseController;
import com.dony.common.core.domain.AjaxResult;
import com.dony.common.core.page.TableDataInfo;
import com.dony.common.utils.bean.BeanUtils;
import com.dony.shop.domain.GlobalProduct;
import com.dony.shop.domain.vo.GlobalProductVo;
import com.dony.shop.domain.vo.PublishShopVo;
import com.dony.shop.service.IGlobalProductService;
import com.dony.shop.service.IPublishTaskService;
import com.dony.shop.service.ShopeeAuthService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@Slf4j
@RestController
@RequestMapping("/shopee/auth")
public class ShopeeAuthController extends BaseController {

    @Resource
    private ShopeeAuthService shopeeAuthService;

    /**
     * 生成授权链接
     */
    @RequestMapping("/createAccessTokenUrl")
    public AjaxResult createAccessTokenUrl() {
        String url = shopeeAuthService.createAccessTokenUrl();
        return AjaxResult.success(url);
    }

    /**
     * 获取 access_token
     */
    @RequestMapping("/saveAccessToken/{userId}")
    public AjaxResult saveAccessToken(@RequestParam("code") String code,
                                      @RequestParam(name = "shop_id", required = false) Long shopId,
                                      @RequestParam(name = "main_account_id", required = false) Long mainAccountId,
                                      @PathVariable("userId") Long userId) {
        shopeeAuthService.saveAccessToken(code, mainAccountId, shopId, userId);
        return AjaxResult.success("授权完成，请关闭当前页面");
    }


}
